﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//------------//
using QLKTX1._0.DTO;
using QLKTX1._0.DB;
using System.Data.SqlClient;
using System.Data;
//....................
namespace QLKTX1._0.DAO
{
    class DotDangKyDAO
    {
        public DotDangKyDTO getObject(string maDot)
        {
            ConnectDB con = new ConnectDB();

            DotDangKyDTO dotDangKy = new DotDangKyDTO();

            string sql = "";

            sql += "SELECT dbo.Dot_DangKy.maDot, dbo.Dot_DangKy.ngayBatDau, dbo.Dot_DangKy.ngayKetThuc, dbo.Dot_DangKy.tenDot, dbo.namHoc.maNamHoc,";
            sql +=" dbo.namHoc.tenNamHoc FROM dbo.Dot_DangKy INNER JOIN";
            sql +=" dbo.namHoc ON dbo.Dot_DangKy.maNamHoc = dbo.namHoc.maNamHoc";
            sql += "WHERE dbo.Dot_DangKy.maDot='"+maDot+"'";

            DataTable dt = con.getDataTable(sql);

            for (int i = 0; i < dt.Rows.Count; i++)
            {


                dotDangKy.MaDot = dt.Rows[i]["maDot"].ToString();

                dotDangKy.NgayBatDau = DateTime.Parse(dt.Rows[i]["ngayBatDau"].ToString());

                dotDangKy.NgayKetThuc = DateTime.Parse(dt.Rows[i]["ngayKetThuc"].ToString());

                dotDangKy.TenDot = dt.Rows[i]["tenDot"].ToString();

                NamHocDTO nh = new NamHocDTO();

                nh.MaNamHoc = Int32.Parse(dt.Rows[i]["maNamHoc"].ToString());

                nh.TenNamHoc = dt.Rows[i]["tenNamHoc"].ToString();

                dotDangKy.MaNamHoc = nh;

                //-------------------------//    
            }
            return dotDangKy;
        }
        public static List<DotDangKyDTO> dsDotDangKy()
        {
            List<DotDangKyDTO> dsDotDangKy = new List<DotDangKyDTO>();

            ConnectDB con = new ConnectDB();

            string sql = "";

            sql += "SELECT dbo.Dot_DangKy.maDot, dbo.Dot_DangKy.ngayBatDau, dbo.Dot_DangKy.ngayKetThuc, dbo.Dot_DangKy.tenDot, dbo.namHoc.maNamHoc,";
            sql +=" dbo.namHoc.tenNamHoc FROM dbo.Dot_DangKy INNER JOIN";
            sql +=" dbo.namHoc ON dbo.Dot_DangKy.maNamHoc = dbo.namHoc.maNamHoc";

            DataTable dt = con.getDataTable(sql);

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DotDangKyDTO dotDangKy = new DotDangKyDTO();

                dotDangKy.MaDot  = dt.Rows[i]["maDot"].ToString();

                dotDangKy.NgayBatDau = DateTime.Parse(dt.Rows[i]["ngayBatDau"].ToString());

                dotDangKy.NgayKetThuc = DateTime.Parse(dt.Rows[i]["ngayKetThuc"].ToString());

                dotDangKy.TenDot = dt.Rows[i]["tenDot"].ToString();

                NamHocDTO nh = new NamHocDTO();

                nh.MaNamHoc = Int32.Parse(dt.Rows[i]["maNamHoc"].ToString());

                nh.TenNamHoc = dt.Rows[i]["tenNamHoc"].ToString();

                dotDangKy.MaNamHoc = nh;

                //-------------------------//              
              
                dsDotDangKy.Add(dotDangKy);
            }

            return dsDotDangKy;
        }

        public static bool themDotDangKy(DotDangKyDTO d){
            return false;
        }

        public static bool capNhatDotDangKy(DotDangKyDTO d)
        {
            return false;
        }

        public static bool xoaDotDangKy(DotDangKyDTO d)
        {
            return false;
        }
    }
}
